package basics.strings;
import java.io.File;


public class ReverseStr {

	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String str=createStr(120);
		String str1;
		String str2;
		String str3;
		
		//System.out.println(str);
		
		long startTime = System.currentTimeMillis();
		str1=reverseStr(str);
		long endTime = System.currentTimeMillis();
		long totaltime=endTime-startTime;
		System.out.println("execution time of reverseStr() is :" + totaltime);
		
		startTime = System.currentTimeMillis();
		str1=reverseStr(str);
		endTime = System.currentTimeMillis();
		totaltime=endTime-startTime;
		System.out.println("execution time of reverseStr2() is :" + totaltime);
		
		startTime = System.currentTimeMillis();
		str1=reverseStr(str);
		endTime = System.currentTimeMillis();
		totaltime=endTime-startTime;
		System.out.println("execution time of reverseStr3() is :" + totaltime);
		
		/*
		System.out.println(reverseStr(str));
		System.out.println(reverseStr2(str));
		System.out.println(reverseStr3(str));
		 */

	}
	
	public static String createStr(int size)
	{
		String s="";
		for(int n=0; n<size; n++)
		{
			for(int i=0; i<10; i++)
			{
				s=s+"-"+i;
			}
		}
		s=s+"-";
		return s;
	}
	public static String reverseStr(String s)
	{
		String ans="";
		int l=s.length();
		for(int i=l-1; i>=0; i--)
		{
			char tmp=s.charAt(i);
			ans=ans+tmp;
		}
		return ans;
	}
	
	public static String reverseStr2(String s)
	{
		char[] charArr=s.toCharArray();
		
		for(int i=0, n=charArr.length-1; i<charArr.length/2; i++,n--)
		{
			char tmp=charArr[i];
			charArr[i]=charArr[n];
			charArr[n]=tmp;
		}
		
		s=new String(charArr);
		return s;
	}
	
	
	public static String reverseStr3(String s)
	{
		if(s.length()==1)
			return s;
		else
		{
			return reverseStr3(s.substring(1)) + s.charAt(0);
		}
	}
	
}
